import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== data
const  categoryData = [
	{ name:'全部', 		value:'' },
	{ name:'单一项目', 	value:'25001' },
	{ name:'从属项目', 	value:'25002' },
	{ name:'组合项目', 	value:'25003' },
	{ name:'营销项目', 	value:'25004' },
]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag:{},
		selectedKeys: [],
		// 搜索表单列表
		forms : [
			{ label: '项目代码',		name: 'kind_code' },
			{ label: '项目全称',		name: 'kind_name' },
			{ label: '助记码',		name: 'debit_code' },
			{ label: '项目分类',		name: 'category', type:'select', data:categoryData },
			{ label: '备注',		name: 'memo' },
			{ label: '岗位',		name: 'project_id', type:'select' },
		],
		formData : [
			{ label: '公司名称',		name: 'comp_id',	type: 'select', half:true, required:true, idStr:'uuid', nameStr:'company_name' },
		]
	}
	
	model = {}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms, formData } = this.state
		$fn.setModalRows(forms, ['project_id'], ()=>{
			$cache.then( async f => {
				// 岗位
				$fn.setRow(forms, 'project_id',  await f.getCache({ api: 'gang_wei' }))
				this.setState({ forms })
			})
		})
		$fn.setModalRows(formData, ['comp_id'], ()=>{
			$cache.then( async f => {
				// 公司名称
				await $fn.setRowc(formData, 'comp_id',  async () => await f.getCache({ api:'company' } ))
				//
				this.setState({  formData })
			})
		})
	}
	
	open = () => {
		this.modal.open()
		this.query = { kind_status:2 }
		// 阻止重复加载数据
		this.getSelect()
		this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this, 'kind-info/index')
	

	// 表单
	cols = [
		{ title: '项目分类', 	dataIndex: 'category_name', 		width:100 },
		{ title: '项目代码', 	dataIndex: 'kind_code', 			width:100 },
		{ title: '项目名称', 	dataIndex: 'kind_name', 			width:150 },
		{ title: '项目属性', 	dataIndex: 'kind_type_name', 		width:100 },
		{ title: '检测方法', 	dataIndex: 'check_method_name', 	width:150 },
		{ title: '岗位', 		dataIndex: 'job_name', 				width:100 },
		{ title: '助记码', 		dataIndex: 'debit_code', 			width:100 },
		{ title: '价格', 		dataIndex: 'total_price', 			...$fn.table.num },
		{ title: '项目排序', 	dataIndex: 'sort', 					...$fn.table.num },
		{ title: '备注', 		dataIndex: 'memo', 					width:220 },
	]
	
	render(){
		return TableModal.call(this,{ 
			title:'复制项目到', width:'90%', height:'70%',  table:{ width:1200 }, api:'specimen/copykind',
			getSubmit: () => {
				const comp_id = this.formRef.getName(['comp_id'])
				return { comp_id, uuids: this.state.selectedKeys}
			},
			
		})
	}
}

export default Index